package com.ccl.bigevent.controller;

import com.ccl.bigevent.pojo.Category;
import com.ccl.bigevent.pojo.Result;
import com.ccl.bigevent.service.CategoryService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Title: CategoryController
 * @Author ccl
 * @Package IntelliJ IDEA
 * @Date 2024/10/19 16:36
 * @description:
 */
@RestController
@RequestMapping("/category")
@Slf4j
@Validated
public class CategoryController {

    @Resource
    private CategoryService categoryService;

    @PostMapping()
    public Result add(@RequestBody @Validated(Category.Add.class) Category category){
        categoryService.add(category);
        return Result.success();
    }

    @GetMapping
    public Result<List<Category>> list(){
        List<Category> cs = categoryService.list();
        return Result.success(cs);
    }

    @GetMapping("detail")
    public Result<Category> detail(Integer id){
        Category category = categoryService.findById(id);
        return Result.success(category);
    }

    @PutMapping()
    public Result update(@RequestBody @Validated(Category.Update.class) Category category){
        categoryService.update(category);
        return Result.success();
    }

    @DeleteMapping()
    public Result delete(Integer id){
        categoryService.delete(id);
        return Result.success();
    }

}
